﻿using WarehouseManagementSystem.Entities;
using WarehouseManagementSystem.Services.IServices;

namespace WarehouseManagementSystem.DAL;

public class WarehouseRepository(ISqliteService sqliteService) : RepositoryBase(sqliteService),IRepository<Warehouse>
{
    public async Task<int> Insert(Warehouse entity) => await db.InsertAsync(entity);

    public async Task<int> Update(Warehouse entity) => await db.UpdateAsync(entity);

    public async Task<int> Delete(Warehouse entity) => await db.DeleteAsync(entity);
    
    public async Task<List<Warehouse>> GetAll() => await db.Table<Warehouse>().ToListAsync();

    public Task<List<Warehouse>> FindAll(string keyWords) 
        => db.Table<Warehouse>().Where(x => x.Name.Contains(keyWords)).ToListAsync();

    public async Task<Warehouse> FindFirst(string keyWords)
        => await db.Table<Warehouse>().FirstAsync(x => x.Name.Contains(keyWords));
}